import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import babel from '@rollup/plugin-babel'
import copy from 'rollup-plugin-copy'
import serve from 'rollup-plugin-serve'
import pkg from './package.json'

const path = require('path')
const extensions = ['.js', '.jsx', '.ts', '.tsx']
const isDev = process.env.NODE_ENV !== 'production'

// Base Plugins
const plugins = [
  // Allows node_modules resolution
  resolve({ extensions }),
  // Allow bundling cjs modules. Rollup doesn't understand cjs
  commonjs(),
  // Compile TypeScript/JavaScript files
  babel({
    extensions,
    exclude: "node_modules/**", // 只编译我们的源码
    // runtimeHelpers: true,
  }),
]

// 组件配置
const config = {
  input: "./src/index.ts",
  // Specify here external modules which you don't want to include in your bundle
  // exp: 'lodash','moment' etc.
  external: [],
  plugins: [
    ...plugins,
    ...( isDev ? [
      copy({
        targets: [
          {src: 'src/example/index.html', dest: 'docs'}
        ]
      }),
      serve({
        contentBase: 'docs'
      }),
    ] : [])
  ],
  output: [
    {
      file: isDev ? 'docs/index.umd.js' : pkg.main,
      format: "umd",
      name: 'logUtils'
    },
    {
      file: isDev ? 'docs/index.esm.js' : pkg.module,
      format: "es",
    },
  ],
};

// app 配置
const appConfig = {
  input: "./docs/app.ts",
  plugins,
  output: {
    file: 'docs/app.js',
    format: 'es'
  }
}



export default [config, /* appConfig */]